home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / pdftops / xpdf / h / GfxFont < prev    next >
Text File  |  1996-06-08  |  2KB  |  106 lines

  1. //========================================================================
  2. //
  3. // GfxFont.h
  4. //
  5. // Copyright 1996 Derek B. Noonburg
  6. //
  7. //========================================================================
  8.  
  9. #ifndef GFXFONT_H
  10. #define GFXFONT_H
  11.  
  12. #ifdef __GNUC__
  13. //#pragma interface
  14. #endif
  15.  
  16. #include "gtypes.h"
  17. #include "GString.h"
  18.  
  19. class Dict;
  20.  
  21. //------------------------------------------------------------------------
  22. // GfxFont
  23. //------------------------------------------------------------------------
  24.  
  25. #define fontFixedWidth (1 << 0)
  26. #define fontSerif      (1 << 1)
  27. #define fontSymbolic   (1 << 2)
  28. #define fontItalic     (1 << 6)
  29. #define fontBold       (1 << 18)
  30.  
  31. class GfxFont {
  32. public:
  33.  
  34.   // Constructor.
  35.   GfxFont(char *tag1, Dict *fontDict);
  36.  
  37.   // Destructor.
  38.   ~GfxFont();
  39.  
  40.   // Get font tag.
  41.   GString *getTag() { return tag; }
  42.  
  43.   // Does this font match the tag?
  44.   GBool matches(char *tag1) { return !tag->cmp(tag1); }
  45.  
  46.   // Get base font name.
  47.   GString *getName() { return name; }
  48.  
  49.   // Get font descriptor flags.
  50.   GBool isFixedWidth() { return flags & fontFixedWidth; }
  51.   GBool isSerif() { return flags & fontSerif; }
  52.   GBool isSymbolic() { return flags & fontSymbolic; }
  53.   GBool isItalic() { return flags & fontItalic; }
  54.   GBool isBold() { return flags & fontBold; }
  55.  
  56.   // Get width of a character.
  57.   double getWidth(Guchar c) { return widths[c]; }
  58.   double getWidth(GString *s);
  59.  
  60.   // Get encoded character name.
  61.   char *getCharName(int code) { return encoding[code]; }
  62.  
  63.   // Look up a character name in an encoding.
  64.   int lookupCharName(char *name, char **enc, int encSize, int hint);
  65.  
  66. private:
  67.  
  68.   void makeEncoding(Dict *fontDict, char **builtinEncoding);
  69.   void makeWidths(Dict *fontDict, char **builtinEncoding,
  70.           int builtinEncodingSize, Gushort *builtinWidths);
  71.  
  72.   GString *tag;
  73.   GString *name;
  74.   int flags;
  75.   double widths[256];
  76.   char *encoding[256];
  77. };
  78.  
  79. //------------------------------------------------------------------------
  80. // GfxFontDict
  81. //------------------------------------------------------------------------
  82.  
  83. class GfxFontDict {
  84. public:
  85.  
  86.   // Build the font dictionary, given the PDF font dictionary.
  87.   GfxFontDict(Dict *fontDict);
  88.  
  89.   // Destructor.
  90.   ~GfxFontDict();
  91.  
  92.   // Get the specified font.
  93.   GfxFont *lookup(char *tag);
  94.  
  95.   // Iterative access.
  96.   int getNumFonts() { return numFonts; }
  97.   GfxFont *getFont(int i) { return fonts[i]; }
  98.  
  99. private:
  100.  
  101.   GfxFont **fonts;        // list of fonts
  102.   int numFonts;            // number of fonts
  103. };
  104.  
  105. #endif
  106.